#include "Drawable.h"

Drawable::Drawable()
{
}

Drawable::~Drawable()
{
}

SDL_Surface* Drawable::LoadImage(std::string filename)
{
	//Temporary holders for optimization
	SDL_Surface* loadedImage = NULL;
	SDL_Surface* optimizedImage = NULL;

	//Load the image

	loadedImage = SDL_LoadBMP(filename.c_str());

	if(loadedImage != NULL)
	{
		optimizedImage = SDL_DisplayFormat(loadedImage);

		SDL_FreeSurface(loadedImage);
	}

	return optimizedImage;
}

void Drawable::DrawImage(SDL_Surface* destinationSurface, SDL_Surface* image, int x, int y)
{
	//Rectangle to hold offsets
	SDL_Rect offsetRect;

	//Set the offsets
	offsetRect.x = x;
	offsetRect.y = y;

	//Blit the surface
	SDL_BlitSurface(image, NULL, destinationSurface, &offsetRect);
}

void Drawable::DrawImage(SDL_Surface* destinationSurface, SDL_Surface* image, int x, int y, int xOffset, int yOffset, int w, int h)
{
	//Rectangle to hold possition
	SDL_Rect possitionRect;

	//Set the offsets
	possitionRect.x = x;
	possitionRect.y = y;

	//Rectangle to hold section of sprite to blit
	SDL_Rect sourceRect;

	sourceRect.x = xOffset;
	sourceRect.y = yOffset;
	sourceRect.w = w;
	sourceRect.h = h;

	//Blit the surface
	SDL_BlitSurface(image, &sourceRect, destinationSurface, &possitionRect);
}